home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX Installation Tools & Overlays 2002 November
/
SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso
/
dist
/
cluster_admin.idb
/
usr
/
cluster
/
bin
/
cdbRestore.z
/
cdbRestore
Wrap
Text File
|
2002-10-15
|
7KB
|
197 lines
#!/bin/ksh
#
# Copyright (C) 1998, Silicon Graphics, Inc.
# All Rights Reserved.
#
# UNPUBLISHED -- Rights reserved under the copyright laws of the United
# States. Use of a copyright notice is precautionary only and does not
# imply publication or disclosure.
#
# THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF
# SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR
# DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN
# PERMISSION OF SILICON GRAPHICS, INC.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
# Use, duplication or disclosure by the Government is subject to
# restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph
# (c)(1)(ii) of the Rights in Technical Data and Computer Software
# clause at DFARS 252.227-7013 and/or in similar or successor clauses
# in the FAR, or the DOD or NASA FAR Supplement. Unpublished-- rights
# reserved under the copyright laws of the United States.
# Contractor/manufacturer is Silicon Graphics, Inc.,
# 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
#
#
# cdbRestore - This script restore cdb from a cdb backup file taken using
# cdbBackup script. See comments on USAGE below for details.
#
SCRIPT_NAME=`/usr/bin/basename $0`
#
# The usage string for this script.
#
# The user has to provide the cdb backup file name using option -f from which
# the cdb is to be restored. By default the cdb is restored under directory
# /var/cluster/cdb as /var/cluster/cdb/cdb.db and /var/cluster/cdb/cdb.db#/*.
# If the cdb backup file is not a full path name and is not a relative path of
# the form aa/bb/<cdb backup file>, then it is assumed that cdb backup file
# is present in the default backup directory /var/cluster/cdb-backup. The user
# can specify a different backup directory using the -d option.
#
# If the user wants the cdb to be retored under a different directory, user
# can provide the full path of the expected cdb header file using the -c
# option. The basename of the cdb header file should be the same as the
# basename of the cdb header file saved in the cdb backup file. Normally, the
# basename for the cdb header file is cdb.db.
# e.g.
# /tmp/cdb/cdb.db
#
USAGESTR="Usage: $SCRIPT_NAME -f backup_filename [-d backup_directory] [-c CDB_header_file]"
#
# DEFAULT values for various variables used in this script
#
# BACKUP_FILE_NAME - User supplied. The name of the cdb backup file.
BACKUP_FILE_NAME=""
# BACKUP_DIR - The directory under which the cdb backup file is present.
BACKUP_DIR=/var/cluster/cdb-backup
# CDB_HEADER_FILE - The cdb header file.
CDB_HEADER_FILE=/var/cluster/cdb/cdb.db
#############
# FUNCTIONS #
#############
#
# signal_handler():
# Arguments: None
# Return value: None
# Description:
# Invoked when user interrupts the script using signal 2 (SIGTERM)
# Removes the partially restored cdb and exits.
#
function signal_handler
{
echo -n "<<interrupted>> cleaning up..."
rm -f ${CDB_DIR}/${CDB_HEADER_FILE}
rm -rf ${CDB_DIR}/${CDB_DATA_ROOT_DIR}
echo "done."
exit 1
}
################
# MAIN PROGRAM #
################
#
# Process the command line arguments
#
while getopts f:d:c:h option
do
case $option in
f) BACKUP_FILE_NAME=$OPTARG;;
d) BACKUP_DIR=$OPTARG;;
c) CDB_HEADER_FILE=$OPTARG;;
h | \?) echo $USAGESTR
exit 1;;
esac
done
# Confirm that the user provided the backup file name. If not print usage
# and exit.
if [ "a$BACKUP_FILE_NAME" = "a" ]; then
echo "Error: $USAGESTR"
exit 1
fi
# If backup file name is not full path and it is not of the form aa/bb
# and backup directory BACKUP_DIR is not "" then prepend BACKUP_DIR to it.
# If BACKUP_FILE_NAME is not full path
echo $BACKUP_FILE_NAME | grep "^/" > /dev/null 2>&1
if [ $? -ne 0 ]; then
# If BACKUP_FILE_NAME is not of the form aa/bb
echo $BACKUP_FILE_NAME | grep "/" > /dev/null 2>&1
if [ $? -ne 0 ]; then
# If BACKUP_DIR is not ""
if [ "a$BACKUP_DIR" != "a" ]; then
# Prepend BACKUP_DIR to BACKUP_FILE_NAME
BACKUP_FILE_NAME=${BACKUP_DIR}/${BACKUP_FILE_NAME}
fi
fi
fi
# Confirm that backup file exists.
if [ ! -a "${BACKUP_FILE_NAME}" ]; then
echo "Error: $SCRIPT_NAME: File ${BACKUP_FILE_NAME} does not exist."
exit 1
fi
# Get the cdb parent directory name CDB_DIR from cdb header file name
CDB_DIR=`dirname $CDB_HEADER_FILE`
# Confirm that cdb parent directory exists
if [ ! -d "$CDB_DIR" ] || [ ! -w "$CDB_DIR" ]; then
echo "Error: $SCRIPT_NAME: CDB directory $CDB_DIR doesn't exist"
exit 1
fi
# Confirm that cdb header file does not exist.
if [ -a "$CDB_HEADER_FILE" ]; then
echo "Error: $SCRIPT_NAME: Database header file $CDB_HEADER_FILE already exists."
exit 1
fi
# Get the cdb data directory name from the cdb header file name
CDB_DATA_ROOT_DIR=${CDB_HEADER_FILE}"#"
# Confirm that cdb data directory does not exist.
if [ -a "$CDB_DATA_ROOT_DIR" ]; then
echo "Error: $SCRIPT_NAME: Database data directory $CDB_DATA_ROOT_DIR already exists."
exit 1
fi
# Extract the basenames for cdb header file and cdb data directory.
# This information will be needed when extracting files from the cdb dump file.
CDB_HEADER_FILE=`basename $CDB_HEADER_FILE`
CDB_DATA_ROOT_DIR=`basename $CDB_DATA_ROOT_DIR`
# Added for debugging
#echo "BACKUP_FILE_NAME = $BACKUP_FILE_NAME"
#echo "CDB_DIR = $CDB_DIR"
#echo "CDB_HEADER_FILE = $CDB_HEADER_FILE"
#echo "CDB_DATA_ROOT_DIR = $CDB_DATA_ROOT_DIR"
# Extract the cdb files from the user supplied cdb dump.
# When interrupted by user, remove cdb header file and cdb data directory
# and exit.
trap signal_handler 2
echo -n "Installing cdb files from cdb backup file ${BACKUP_FILE_NAME} "
echo -n "under directory ${CDB_DIR} ..."
cat ${BACKUP_FILE_NAME} | /usr/bsd/uncompress | ( cd $CDB_DIR; tar xf - $CDB_HEADER_FILE $CDB_DATA_ROOT_DIR)
echo "done."
exit 0